#!/usr/bin/env python
# encoding: utf-8
"""
fixbadspectra.py

Created by August Muench on 2010-04-01.
Copyright (c) 2010 Smithsonian Astrophysical Observatory. All rights reserved.

Script to fix various kinds of badly formatted spectra.
Including:
    "SpeXTool FITS Format" : a 2D array of flux,pixel and error values lacking
        any and all WCS keywords necessary to reinterpret. This is partially
        because orders have different pixel scales so a simple linear 2D 
        mapping doesn't work. The correct solution is to use a FITS bintable.
"""

import sys
import getopt

import atpy
import numpy as np

from beetlefixes import fixBadSpeX

help_message = '''
The help message goes here.
'''


class Usage(Exception):
    def __init__(self, msg):
        self.msg = msg


def main(argv=None):
    if argv is None:
        argv = sys.argv
    try:
        try:
            opts, args = getopt.getopt(argv[1:], "ho:v", ["help", "output="])
        except getopt.error, msg:
            raise Usage(msg)

        # option processing
        for option, value in opts:
            if option == "-v":
                verbose = True
            if option in ("-h", "--help"):
                raise Usage(help_message)
            if option in ("-o", "--output"):
                output = value

    except Usage, err:
        print >> sys.stderr, sys.argv[0].split("/")[-1] + ": " + str(err.msg)
        print >> sys.stderr, "\t for help use --help"
        return 2


if __name__ == "__main__":
    sys.exit(main())
